package com.blkj.framework.aspectj;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author 北浪 2021/11/15
 */
@Aspect
@Component
public class LogAspectj {

    private static final TimeInterval timer = DateUtil.timer();

    //植入点
    @Pointcut("@annotation(com.blkj.common.annotation.Log)")
    public void logPointCut()
    {
    }

    @Before("logPointCut()")
    public void logBefore(){
        timer.intervalRestart();//返回花费时间，并重置开始时间
    }

    @AfterReturning("logPointCut()")
    public void logAfter(){
        System.out.println("花费时间：" + timer.interval() + "ms");
    }
}
